<?php
/**
 * User Service in Service Module
 *
 * @author Olivier Parent
 * @copyright Copyright (c) 2011 Artevelde University College Ghent
 */
class Service_UserService
{
    public function __construct()
    {

    }

    /**
     * @return Ahs_VO_User
     */
    public function getUser()
    {
        $userMapper = new Application_Model_UserMapper();
        $user = $userMapper->fetchById(1);

        $userVO = $this->_toUserVO($user);

        return $userVO;
    }

    /**
     * @return array
     */
    public function getUsers()
    {   
        $userMapper = new Application_Model_UserMapper();
        $users = $userMapper->fetchAll();

        $userVOs = $this->_toUserVOs($users);

        return $userVOs;
    }

    /**
     * @return array
     */
    public function getUsersList()
    {
        return $this->getUsers();
    }

    /**
     * @param Application_Model_User $user
     * @return VO_User
     */
    private function _toUserVO(Application_Model_User $user)
    {
        $userVO = new VO_User();
        $userVO->id         = $user->Id;
        $userVO->email      = $user->Email;
        $userVO->givenname  = $user->Givenname;
        $userVO->familyname = $user->Familyname;

        return $userVO;
    }

    /**
     * @param array $users
     * @return array
     */
    private function _toUserVOs($users = array())
    {
        $userVOs = array();
        foreach ($users as $user) {
            $userVOs[] = $this->_toUserVO($user);
        }

        return $userVOs;
    }

}
